package _98综合练习;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import _05处理流.Student;
import _05处理流.Wujiang;

public class FileControl {
	private static void testRead() throws IOException, ClassNotFoundException 
	{
		ObjectInputStream in = new ObjectInputStream(new FileInputStream("d:/stu.data"));
		
		/*Student stu = (Student) in.readObject();
		System.out.println(stu);*/
		List<Student> stus=(List<Student>)in.readObject();
		System.out.println(stus);
		
		in.close();
		
	}

	private static void testWrite() throws FileNotFoundException, IOException {
		// TODO Auto-generated method stub
		
		// 1 打开流
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("d:/stu.data"));
		
		
		// 2. 写入对象
		List<Student> stus = new ArrayList<>();
		stus.add(new Student(1,"张三",18));
		stus.add(new Student(2,"刘备",18));
		stus.add(new Student(3,"张飞",20));
		out.writeObject(stus);
		
		// 3. 关闭文件
		out.close();
		
	}
}